var t = require("../../utils/api.js"), a = getApp();

require("../../utils/disapi.js");

Page({
    data: {},
    onLoad: function(o) {
        var e = this;
        wx.getLocation({
            type: "wgs84",
            success: function(n) {
                console.log(n);
                var l = {
                    lat: n.latitude,
                    lng: n.longitude,
                    types: 20
                };
                if (a.globalData.latitude = n.latitude, a.globalData.longitude = n.longitude, "selected" == o.act) {
                    console.log(o);
                    var i = o.city, s = o.cid;
                    e.setData({
                        city: i,
                        cid: s
                    });
                } else {
                    var n = e.getLocal(l.lat, l.lng);
                    console.log(n);
                    s = "";
                }
                t.getNearestHead({
                    lat: l.lat,
                    lng: l.lng,
                    cid: s,
                    openid: a.globalData.openid
                }).then(function(o) {
                    console.log(o), 0 == o.errno && 0 !== o.data.data.length && setTimeout(function() {
                        console.log(3), e.setData({
                            showPrevLoading: !e.data.showPrevLoading,
                            loadingwait: !0,
                            showContent: !1
                        });
                    }, 1e3), 1 == o.errno && setTimeout(function() {
                        console.log(1), e.setData({
                            loadingwait: !1,
                            showContent: !1
                        });
                    }, 1e3), console.log(o.data.data), a.globalData.location = !0;
                    var n = o.data.data, l = o.data.history;
                    console.log(l);
                    for (var i = [], s = 0; s < n.length; s++) n[s].m = parseFloat(n[s].m / 1e3).toFixed(2), 
                    i.push(n[s]);
                    e.setData({
                        recommend: i,
                        location: !0,
                        history: l
                    }), t.getTeamOpenid({
                        openid: wx.getStorageSync("openid")
                    }).then(function(t) {
                        console.log(t), 0 == t.errno && "" != t.data.head_info && wx.setStorageSync("head_info", t.data.head_info), 
                        wx.getStorageSync("head_info") ? e.setData({
                            active: wx.getStorageSync("head_info")
                        }) : e.setData({
                            active: t.data.head_info
                        });
                    });
                });
            },
            fail: function(t) {
                console.log(t), e.setData({
                    getlocation: !0,
                    location: !1
                }), console.log(e.data.location);
            },
            complete: function(t) {
                console.log(t);
            }
        });
    }
});